package jzoffer;

/**
 * @author MaoLin Wang
 * @date 2020/10/8 9:49 上午
 */
public class _24反转链表 {
    public static ListNode reverseList(ListNode head) {
        if (head==null || head.next==null){
            return head;
        }
        ListNode newHead=null;
        ListNode temp=head;
        ListNode next=head.next;
        while (temp!=null){
            temp.next=newHead;
            newHead=temp;
            temp=next;
            if (next!=null){

                next=next.next;
            }
        }
        return newHead;
    }

    public static void main(String[] args) {
        ListNode node=new ListNode(1);
        ListNode nod2e=new ListNode(2);
        ListNode nod3e=new ListNode(3);
        ListNode no4de=new ListNode(4);
        node.next=nod2e;
        nod2e.next=nod3e;
        nod3e.next=no4de;

        reverseList(node).print();


    }
}
